/**
 * Created by shen'jia on 15/6/11.
 */
;
(function () {
'use strict';
angular.module('services.omdisplay.sysPerform',[])
  .service('oldSystemPerformData',oldSystemPerformData)//页面数据
  .service('oldSystemPerformOption',oldSystemPerformOption)//echarts
  .factory('oldSystemPerformDayAndDay',oldSystemPerformDayAndDay)//开始时间结束时间相差3天提示
  .factory('oldSystemPerformProcessData',oldSystemPerformProcessData)//响应时间处理
  .factory('oldSystemPerformProcessStageData',oldSystemPerformProcessStageData)//阶段响应时间处理
  .factory('oldSystemPerformURL',oldSystemPerformURL)//请求Url
  .factory('oldSystemPerformBox',oldSystemPerformBox)//获取用户选择
  .factory('oldSystemPerformCRUD',oldSystemPerformCRUD)//新增，修改，删除响应时间
  .service('oldSystemPerformAddData',oldSystemPerformAddData);//add数据

//页面数据
function oldSystemPerformData (COREDATA) {
 var year=new Date().getFullYear();
 var month = new Date().getMonth();
 var day=new Date();
  this.system = COREDATA.SYSTEM;         //业务系统
  this.business = [{businessCode:'01',businessName:'签约'}];                    //业务
  this.province = COREDATA.PROVINCES;    //省份
  this.timeTypes = [{timeTypeName: '天', timeTypeCode: '1'},{timeTypeName: '月', timeTypeCode: '3'}];//时间粒度
  this.startTime = new Date();           //开始时间
  this.endTime = new Date();             //结束时间
  this.translate = {                     //下拉框选择后的数据
    systemCode:COREDATA.SYSTEM[0].systemCode,
    businessCode:'02',
    provinceCode:'200',
    system:[],
    business:[],
    province:[],
    timeTypeCode:'1',
    startTime:new Date(year,month,day-5),
    endTime:new Date(),
  };
  this.checckBox = [];
  this.chaProvince = '';
  this.modifyData = {
    responseTimeMax : [],
    responseTimeMin : [],
    currentAvgResponseTime : [],
    historyAvgResponseTime : []
  }
}

//[oldSystemPerformOption echarts构造函数]
function oldSystemPerformOption(){


  this.sysPerformChart = {
    title : {text: '',x: 'center'},
    tooltip : {trigger: 'axis', axisPointer : {            // 坐标轴指示器，坐标轴触发有效
            type : 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
        }},
    animation : false,
    grid : {width: 980, x2: 120, x: 70},
    legend : {
      show: true, orient: 'vertical',
      x: 'right', y: 50,
      data:['最低阀值' ,'最高阀值' ,'当前平均' ,'历史平均']
    },

    xAxis : [{type: 'category', boundaryGap: true, splitLine: false, axisLine: {onZero: false}, data: ['周一'], splitArea: true}],
    yAxis : [{name: '响应时间', type: 'value', axisLabel: {formatter: '{value}s'}}],
    series : [
      {name: '最高阀值', type: 'line', smooth: true, data: [220, 182], symbolSize: 2, showAllSymbol: true},
      {name: '最低阀值', type: 'line', smooth: true, data: [120, 132], symbolSize: 2, showAllSymbol: true},
      {
        markLine : {data : [{type : 'max', name: '最大值'},{type: 'min', name: '最小值'}]},
        name: '当前平均', type: 'line', smooth: true, data: [150, 232], symbolSize: 2, showAllSymbol: true
      },
      {name: '历史平均', type: 'line', smooth: true, data: [320, 332], symbolSize: 2, showAllSymbol: true}
    ]
  };


  this.throughputChart = {
    title : {text: '业务吞吐量',x: 'center'},
    tooltip : {trigger: 'axis',axisPointer : {            // 坐标轴指示器，坐标轴触发有效
            type : 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
        },},
    animation : false,
    grid : {x: 100, x2: 100, y: 35},
    xAxis : [{type: 'category', boundaryGap: true, splitLine: false, axisLine: {onZero: false}, data: ['周一','周二'],axisLabel:{show: true,rotate: 50}, splitArea: true} ],
    
    yAxis : [{name: '业务办理数', type: 'value', axisLabel: {formatter: '{value}'}}],
    series : [
      {name: '业务办理数', type: 'line', smooth: true, data: [220, 182], symbolSize: 2, showAllSymbol: true}
    ]
  };
  this.concurrentChart={
    title : {text: '',x: 'center'},
    tooltip : {trigger: 'axis',  axisPointer : {            // 坐标轴指示器，坐标轴触发有效
            type : 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
        }},
    animation : false,
    grid : {x: 100, x2: 100, y: 35},
    xAxis : [{type: 'category', boundaryGap: true, splitLine: false, data: ['周一','周二'],axisLabel:{show: true,rotate: 50}, splitArea: true}],
    yAxis : [{name: '业务并发数', type: 'value' }],
    series : [
      {name: '业务并发数', type: 'line', data: [220, 182]}
    ]
  }
  this.phasesResChart = {
    title : {text: '',x: 'center'},
    tooltip : {trigger: 'axis',axisPointer : {            // 坐标轴指示器，坐标轴触发有效
            type : 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
        },},
    animation : false,
    grid : {x: 100, x2: 100, y: 35},
    xAxis : [{type: 'category', boundaryGap: true, splitLine: false, data: ['周一','周二'],axisLabel:{show: true,rotate: 50}, splitArea: true}],
    yAxis : [{name: '响应时间', type: 'value' }],
    series : [
      {name: '阶段1', type: 'bar', data: [220, 182]},
      {name: '阶段2', type: 'bar', data: [220, 182]},
      {name: '阶段3', type: 'bar', data: [220, 182]},
      {name: '阶段4', type: 'bar', data: [220, 182]}
    ]
  }
  this.drillChart = {
    title : {text: '',x: 'center'},
    tooltip : {trigger: 'axis',  axisPointer : {            // 坐标轴指示器，坐标轴触发有效
            type : 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
        }},
    animation : false,
    grid : {x: 150, x2: 150, y: 45,y2:60},
    xAxis :[{type: 'category', boundaryGap: true, splitLine: false, data: ['阶段1','阶段2','阶段3','阶段4'], splitArea: true}],
    yAxis : [{name: '阶段响应', type: 'value', axisLabel: {formatter: '{value}s'} }],
    series : [
      {name: '阶段响应', type: 'bar', data: [220, 182]}
    ]
  }
}

//[dayAndDay 时间差3天或者3个月]
function oldSystemPerformDayAndDay(oldSystemPerformData){
  return {
    dAd : dAd,
    dAdOne : dAdOne
  }
  function dAd(){
    var type = oldSystemPerformData.translate.timeTypeCode;
    var start = oldSystemPerformData.translate.startTime;
    var end = oldSystemPerformData.translate.endTime;
    if(type ==='1'){
      return (end - start)/86400000 < 3 ? true : false;
    }else if(type ==='3'){
      return (end.getMonth() - start.getMonth()) < 3 ?  true :  false;
    }
  }
  function dAdOne(){
    var type = oldSystemPerformData.translate.timeTypeCode;
    var start = oldSystemPerformData.translate.startTime;
    var end = oldSystemPerformData.translate.endTime;
    if(type ==='1'){
      return (end - start)/86400000 < 1 ? true : false;
    }else if(type ==='3'){
      return (end.getMonth() - start.getMonth()) < 1 ?  true :  false;
    }
  }
}

//[oldSystemPerformProcessData 处理echarts数据]
function oldSystemPerformProcessData($state,$filter){
  return {
    process:processData
  }
  function processData(echartsObj,option,title,data,noDataZoom,timeType){
    echartsObj.clear();
    var x1 = [];
    var responseTimeMax = [];
    var responseTimeMin = [];
    var currentAvgResponseTime = [];
    var historyAvgResponseTime = [];
    var format=''
    if(timeType==='1'){
        format='yyyy-MM-dd'
    }else{
      var   format='yyyy-MM'
    }
    angular.forEach(data, function(role,key) {//迭代数据分离X轴数组，Y轴数组
      x1.push($filter('date')(role.time,format));
      responseTimeMax.push(role.responseTimeMax === (undefined||null) ? '0' : role.responseTimeMax);
      responseTimeMin.push(role.responseTimeMin === (undefined||null) ? '0' : role.responseTimeMin);
      currentAvgResponseTime.push(role.currentAvgResponseTime === (undefined||null) ? '0' : role.currentAvgResponseTime);
      historyAvgResponseTime.push(role.historyAvgResponseTime === (undefined||null) ? '0' : role.historyAvgResponseTime);
    });
    option.title.text = title;
    if(!noDataZoom){
      option.dataZoom = {show:true, start:0, end:100};
    
      option.tooltip= {
        trigger: 'axis',
        axisPointer : {            // 坐标轴指示器，坐标轴触发有效
            type : 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
        },
      };
    }
    echartsObj.setOption(option);
    echartsObj.setOption({ xAxis :[{data:x1}]  });
    echartsObj.setOption({ series :[{data:responseTimeMax},{data:responseTimeMin},{data:currentAvgResponseTime},{data:historyAvgResponseTime}]  });
   if(noDataZoom){
    echartsObj.on(echarts.config.EVENT.CLICK,function(pp){
      $state.go('sas.oldOMDisplay.sysPerf.stagePerform');
    });
     
   }
  }
}

//[oldSystemPerformProcessStageData 处理stage数据]
function oldSystemPerformProcessStageData(oldSystemPerformOption){
  return {
    process:processData
  }
  function processData(echartsObj,titles,data,scope){//这里echartsObj，options，titles都是数组，
    var x1 = [];
    for(var i=0;i<24;i++){
      if(i<10){
        x1.push('0'+i+':00:00');
      }else{
        x1.push(i+':'+'00:00');
      }
    }
    var businessAcceptNum = [];
    var businessConcurrent = [];
    var phase1ResponseTime = [];
    var phase2ResponseTime = [];
    var phase3ResponseTime = [];
    var phase4ResponseTime = [];
    var options = [
      oldSystemPerformOption.throughputChart,
      oldSystemPerformOption.concurrentChart,
      oldSystemPerformOption.phasesResChart,
      oldSystemPerformOption.drillChart
    ];
    angular.forEach(data, function(role) {//迭代数据分离X轴数组，Y轴数组
      businessAcceptNum.push(role.businessAcceptNum === (undefined||null) ? '0' : role.businessAcceptNum);
      businessConcurrent.push(role.businessConcurrent === (undefined||null) ? '0' : role.businessConcurrent);
      phase1ResponseTime.push(role.phase1ResponseTime === (undefined||null) ? '0' : role.phase1ResponseTime);
      phase2ResponseTime.push(role.phase2ResponseTime === (undefined||null) ? '0' : role.phase2ResponseTime);
      phase3ResponseTime.push(role.phase3ResponseTime === (undefined||null) ? '0' : role.phase3ResponseTime);
      phase4ResponseTime.push(role.phase4ResponseTime === (undefined||null) ? '0' : role.phase4ResponseTime);
    });
    options[0].title.text = titles[0];
    options[1].title.text = titles[1];
    options[2].title.text = titles[2];
    options[3].title.text = titles[3];

    // option.dataZoom = {show:true, start:0, end:100};
    echartsObj[0].setOption(options[0]);
    echartsObj[1].setOption(options[1]);
    echartsObj[2].setOption(options[2]);


    echartsObj[0].setOption({ xAxis :[{data:x1}]  });
    echartsObj[1].setOption({ xAxis :[{data:x1}]  });
    echartsObj[2].setOption({ xAxis :[{data:x1}]  });

    echartsObj[0].setOption({ series :[{data:businessAcceptNum}]});
    echartsObj[1].setOption({ series :[{data:businessConcurrent}]});
    echartsObj[2].setOption({ series :[{data:phase1ResponseTime},{data:phase2ResponseTime},{data:phase3ResponseTime},{data:phase4ResponseTime}]  });

    echartsObj[0].connect([echartsObj[1],echartsObj[2]]);
    echartsObj[1].connect([echartsObj[0],echartsObj[2]]);
    echartsObj[2].connect([echartsObj[0],echartsObj[1]]);

    echartsObj[2].un(echarts.config.EVENT.CLICK);
    echartsObj[2].on(echarts.config.EVENT.CLICK,drillFunc);

    function drillFunc(params){
      scope.isDrill = false;
      var index = x1.indexOf(params.name);
      var t4Data = [
        phase1ResponseTime[index],
        phase2ResponseTime[index],
        phase3ResponseTime[index],
        phase4ResponseTime[index]
      ];
      options[3].title.text = titles[3]+'   '+params.name;
      echartsObj[3].setOption(options[3]);
      echartsObj[3].setOption({ series :[{data:t4Data}]});
      scope.$apply();
    }

  }
}

//[oldSystemPerformURL 页面请求]
function oldSystemPerformURL (Restangular,oldSystemPerformData,CoreService,oldSystemPerformProcessData,oldSystemPerformDayAndDay,oldSystemPerformAddData){
  var dutyParam = function(){
    var geshi = oldSystemPerformData.translate.timeTypeCode ==='1'?'yyyy-MM-dd':'yyyy-MM';

    var paramm = {
      timeType:oldSystemPerformData.translate.timeTypeCode+'',
      startTime:CoreService.dateFormat(oldSystemPerformData.translate.startTime,geshi),
      endTime:CoreService.dateFormat(oldSystemPerformData.translate.endTime,geshi),
      systemCode:oldSystemPerformData.translate.systemCode,
      businessCode:oldSystemPerformData.translate.businessCode,
      provinceCode:oldSystemPerformData.translate.provinceCode
    }
    if(oldSystemPerformData.translate.timeTypeCode !=='1'){
      paramm.startTime =  paramm.startTime + '-01';
      paramm.endTime =  paramm.endTime + '-01';
    }
    return paramm;
  };
  return {
    //查询系统性能
    queryWatchAdd:function (chart,option,title,noDataZoom,dataAdd){
      //console.log(option.clear());
    /*  if(!oldSystemPerformDayAndDay.dAd()){
        if(oldSystemPerformData.translate.timeTypeCode === '1'){
          CoreService.dialog('结束时间不能大于开始时间3天以上');
        }else{
          CoreService.dialog('结束时间不能大于开始时间3个月以上');
        }
        return;
      }*/
      // if(dataAdd.responseTimeMax.length === 0){
      //   chart.clear();
      //   chart.setOption({ series : {data:[]} });
      //   return;
      // }
      var paramm = {};
      if(oldSystemPerformAddData.addDate.timeT === '天'){
        paramm.timeType = '1';
      }else{
        paramm.timeType = '3';
      }
      oldSystemPerformProcessData.process(chart,option,title,dataAdd,noDataZoom,paramm.timeType);//处理echarts
      window.localStorage.sysPerfmCondition = JSON.stringify(paramm);
      
    },

    //查询系统性能
    querySysPerfm:function (chart,option,title,noDataZoom){
      //console.log(option.clear());
    /*  if(!oldSystemPerformDayAndDay.dAd()){
        if(oldSystemPerformData.translate.timeTypeCode === '1'){
          CoreService.dialog('结束时间不能大于开始时间3天以上');
        }else{
          CoreService.dialog('结束时间不能大于开始时间3个月以上');
        }
        return;
      }*/
      var paramm = dutyParam();//处理参数
      Restangular.all('sas/OMdisplay/systemPerformance').post(paramm).then(function(resultData){
        if(resultData.state === '10000'){
          if(resultData.data.length === 0){
            chart.clear();
            chart.setOption({ series : {data:[]} });
            return;
          }
          oldSystemPerformProcessData.process(chart,option,title,resultData.data,noDataZoom,paramm.timeType);//处理echarts
          window.localStorage.sysPerfmCondition = JSON.stringify(paramm);
        }else{
          CoreService.dialog('根据查询条件未查到有关数据','提示('+resultData.state+')');
        }
      });
    },
    //查询单个业务阶段性能
    queryPhases:function (params,callback){
      var paramm = dutyParam();//处理参数
      Restangular.all('sas/OMdisplay/systemPerformance/business').post(paramm).then(callback);
    },
    //根据系统查询业务
    getSysBusiness:function(params){
      var paramss = { systemCode:oldSystemPerformData.translate.systemCode};
      Restangular.all('sas/common/businessQuery').post(paramss).then(function(res){
        if(res && res.data && res.state ==='10000'){
          // if(oldSystemPerformData.business.length > 0 && oldSystemPerformData.business===oldSystemPerformData.business){return};
          oldSystemPerformData.business = res.data;
        }else{
          CoreService.dialog(res.state);
        }
      });
    },
    //add响应时间
    addTime:function (params,callback){
      Restangular.all('sas/OMdisplay/systemPerformance/addTime').post(params).then(callback);
    },
    //delete响应时间
    deleteTime:function (params,callback){
      var params = dutyParam();//处理参数
      params.provinceCode = oldSystemPerformData.checckBox.toString();
      Restangular.all('sas/OMdisplay/systemPerformance/deleteTime').post(params).then(function(result){
        if (result && result.state === '10001') {
          CoreService.dialog('删除失败！');
        } else if(result && result.state === '10003'){
          CoreService.dialog(result.state);
        }else if (result && result.state === '10000') {
          CoreService.dialog('删除成功！');
          // userData.ids= [];
          // userData.userNames=[];
          // userRequest.userQuery();
        } else {
          CoreService.dialog('请求失败');
        }
      });
    },
    //查询系统性能
    modifyQuery:function (chart,option,title){
      /*if(!oldSystemPerformDayAndDay.dAdOne()){
        CoreService.dialog('时间差1天或者1个月');
        return;
      }*/
      var paramm = dutyParam();//处理参数
      Restangular.all('sas/OMdisplay/systemPerformance/modifyTime').post(paramm).then(function(resultData){
        if(resultData.state === '10000'){
          if(resultData.data.length > 0){
            oldSystemPerformData.modifyData.responseTimeMax =[];
            oldSystemPerformData.modifyData.responseTimeMin = [];
            oldSystemPerformData.modifyData.currentAvgResponseTime = [];
            oldSystemPerformData.modifyData.historyAvgResponseTime = [];
            angular.forEach(resultData.data, function(role,key) {//迭代数据分离X轴数组，Y轴数组
              oldSystemPerformData.modifyData.responseTimeMax.push(role.responseTimeMax === (undefined||null) ? '0' : role.responseTimeMax);
              oldSystemPerformData.modifyData.responseTimeMin.push(role.responseTimeMin === (undefined||null) ? '0' : role.responseTimeMin);
              oldSystemPerformData.modifyData.currentAvgResponseTime.push(role.currentAvgResponseTime === (undefined||null) ? '0' : role.currentAvgResponseTime);
              oldSystemPerformData.modifyData.historyAvgResponseTime.push(role.historyAvgResponseTime === (undefined||null) ? '0' : role.historyAvgResponseTime);
            });
          }
        }else{
          CoreService.dialog('根据查询条件未查到有关数据','提示('+resultData.state+')');
        }
      });
    },
    //modify响应时间
    modifySave:function (params){
      var params = dutyParam();
      params.data=[];
      for(var i=0;i<24;i++){
        params.data[i]={
          responseTimeMax:'',
          responseTimeMin:'',
          currentAvgResponseTime:'',
          historyAvgResponseTime:'',
          time:CoreService.dateFormat(oldSystemPerformData.translate.startTime, 'yyyy-MM-dd') + ' '
        };
      }
      for(var i=0;i<24;i++){
        params.data[i].responseTimeMax = oldSystemPerformData.modifyData.responseTimeMax[i];
        params.data[i].responseTimeMin = oldSystemPerformData.modifyData.responseTimeMin[i];
        params.data[i].currentAvgResponseTime = oldSystemPerformData.modifyData.currentAvgResponseTime[i];
        params.data[i].historyAvgResponseTime = oldSystemPerformData.modifyData.historyAvgResponseTime[i];
        if(i<10){
          params.data[i].time = params.data[i].time+'0'+i;
        }else{
          params.data[i].time = params.data[i].time+i;
        }
      }
      Restangular.all('sas/OMdisplay/systemPerformance/modifySave').post(params).then(function(res){
        if (res.state === '10000') {
          CoreService.dialog('修改保存成功');
          // userRequest.userQuery();
        } else if (res && res.state === '10001') {
          CoreService.dialog('保存失败！');
        } else {
          CoreService.dialog('请求失败');
        }
        oldSystemPerformData.modifyData.responseTimeMax = [];
        oldSystemPerformData.modifyData.responseTimeMin = [];
        oldSystemPerformData.modifyData.currentAvgResponseTime = [];
        oldSystemPerformData.modifyData.historyAvgResponseTime = [];
      });
    }
  }
}

/**
 * [oldSystemPerformBox 获取用户选择]
 * @param  {[type]} $cookies [description]
 * @param  {[type]} userData     [description]
 * @return {[type]}              [description]
 */
function oldSystemPerformBox($cookies,oldSystemPerformData) {
  return function (province){
    for(var p in oldSystemPerformData.province){
      if(province === oldSystemPerformData.province[p].provinceName){
        var codeM =  oldSystemPerformData.province[p].provinceCode;
      }
    }
    var index;
    index = oldSystemPerformData.checckBox.indexOf(codeM);
    if (index === -1) {
      oldSystemPerformData.checckBox.push(codeM);
      // oldSystemPerformData.checckBoxNames.push(province);
    } else {
      oldSystemPerformData.checckBox.splice(index, 1);
      // oldSystemPerformData.checckBoxNames.splice(index, 1);
    }
    // oldSystemPerformData.userNameString = oldSystemPerformData.userNames.join(',');
    // oldSystemPerformData.checckBox.length === 1 && angular.forEach(oldSystemPerformData.queryResult.oldSystemPerformData, function(role) {
    //   if(oldSystemPerformData.ids[0] === role.userId ){
    //     $cookies.put('userMngInfo',role);
    //   }
    // });
    // console.log(oldSystemPerformData.checckBox);
  };
}

/**
 * [sysPerformCRUDServer 新增，修改，删除响应时间]
 * @return {[type]}                  [description]
 */
function oldSystemPerformCRUD(oldSystemPerformData, oldSystemPerformURL, COREDATA, CoreService,$mdDialog, oldSystemPerformAddData) {
  return {
    addTime:addT,
    modifyTime:modifyT,
    deleteTime:deleteT,
    resetForm:resetF
  };
  function addT(ev) {
    $mdDialog.show({
      controller: adPerformCtrl,
      templateUrl: 'views/oldOMDisplay/oldSystemPerform/form/add.html',
      targetEvent: ev,
    })
      .then(addSave);
  }
  function addSave (answer){
    // answer.expTime = CoreService.dateFormat(answer.expTime, 'yyyy-MM-dd hh:mm:ss');
    var params = {
      data:[],
      systemCode:'11',
      businessCode:'01',
      provinceCode:'200',
      timeType:'1',
      startTime:'2015-01-01',
      endTime:'2015-01-01'
    };
    for(var i = 0;i<24;i++){
      params.data[i] = {
        currentAvgResponseTime: '',
        historyAvgResponseTime: '',
        responseTimeMax: '',
        responseTimeMin: '',
        time:'2015-01-01'+' '
      };
      if(i<10){
        params.data[i].time = params.data[i].time+'0'+i;
      }else{
        params.data[i].time = params.data[i].time+i;
      }

    }
    answer.time=[];
    for(var i =answer.times.startTime.getTime();i<answer.times.startTime.getTime()+86400000*24;i+=86400000){
      answer.time.push(CoreService.dateFormat(new Date(i),'yyyy-MM-dd'));
    }

    for(var i = 0;i<24;i++){
      params.data[i].currentAvgResponseTime = answer.currentAvgResponseTime[i];
      params.data[i].historyAvgResponseTime = answer.historyAvgResponseTime[i];
      params.data[i].responseTimeMax = answer.responseTimeMax[i];
      params.data[i].responseTimeMin = answer.responseTimeMin[i];
      if(answer.time[i] !== undefined){params.data[i].time = answer.time[i];}else{params.data[i].time = '2015-07-22'}
    };
    // for(var i = 0;i<answer.time.length;i++){
    //   params.data[i].currentAvgResponseTime = answer.currentAvgResponseTime[i];
    //   params.data[i].historyAvgResponseTime = answer.historyAvgResponseTime[i];
    //   params.data[i].responseTimeMax = answer.responseTimeMax[i];
    //   params.data[i].responseTimeMin = answer.responseTimeMin[i];
    //   params.data[i].time = answer.time[i];
    // }
    

    oldSystemPerformAddData.addDate.yuanData = params.data;
    oldSystemPerformAddData.addDate.proName = answer.pageData.province;
    oldSystemPerformAddData.addDate.sysName = answer.pageData.system;
    oldSystemPerformAddData.addDate.busName = answer.pageData.business;
    oldSystemPerformAddData.addDate.timeT = answer.pageData.timeTypeName;
    oldSystemPerformAddData.addDate.isAdd = 'true';
    // oldSystemPerformURL.addTime(params,function(res){      要新增发请求的话，请解开
    //   console.log(res);
    // });
    // console.log(params.data);
    angular.forEach(params.data,function(role,key){
      oldSystemPerformAddData.addDate.data.currentAvgResponseTime[key] = role.currentAvgResponseTime;
      oldSystemPerformAddData.addDate.data.historyAvgResponseTime[key] = role.historyAvgResponseTime;
      oldSystemPerformAddData.addDate.data.responseTimeMax[key] = role.responseTimeMax;
      oldSystemPerformAddData.addDate.data.responseTimeMin[key] = role.responseTimeMin;
    });
    // console.log(oldSystemPerformAddData.addDate.data);
  }

  function modifyT (ev) {
    if (oldSystemPerformData.checckBox.length === 1) {
      $mdDialog.show({
        controller: mdifyPerformCtrl,
        templateUrl: 'views/oldOMDisplay/oldSystemPerform/form/modify.html',
        targetEvent: ev,
      })
        .then(modifyUser);
    } else if (oldSystemPerformData.checckBox.length === 0) {
      CoreService.dialog('请选择要修改的！');
    } else {
      CoreService.dialog('请选择有且一个！');
    }
  }
  function modifyUser(answer) {
    oldSystemPerformURL.modifySave();
  }

  function deleteT (ev) {
    var confirm = $mdDialog.confirm()
      .title('警告')
      .content('确定删除？')
      .ok('确定')
      .cancel('取消')
      .targetEvent(ev);
    $mdDialog.show(confirm).then(sureDel);
    // if (userData.ids.length === 0) {
    //   CoreService.dialog('至少选择一个用户！');
    // }
    // else {
    //   var confirm = $mdDialog.confirm()
    //     .title('警告')
    //     .content('删除用户' + userData.userNameString + '后,用户不可用,确定删除？')
    //     .ok('确定')
    //     .cancel('取消')
    //     .targetEvent(ev);
    //   $mdDialog.show(confirm).then(sureDel);
    // }
  }
  function sureDel() {
    oldSystemPerformURL.deleteTime();
    // userData.userIds.userIds = userData.ids.join(',');
    // userRequest.delUser(userData.userIds, function(result){
    //   if (result && result.state === '10001') {
    //     CoreService.dialog('删除失败！');
    //   } else if(result && result.state === '10007'){
    //     var userName = result.data.join(',');
    //     CoreService.dialog('用户'+userName+'正在使用中不能删除！');
    //   }else if (result && result.state === '10000') {
    //     CoreService.dialog('删除成功！');
    //     userData.ids= [];
    //     userData.userNames=[];
    //     userRequest.userQuery();
    //   } else {
    //     CoreService.dialog('请求失败');
    //   }
    // });
  }
  function resetF () {
    oldSystemPerformData.translate = {                     //下拉框选择后的数据
      systemCode:COREDATA.SYSTEM[0].systemCode,
      businessCode:'02',
      provinceCode:'200',
      system:[],
      business:[],
      province:[],
      timeTypeCode:'1',
      startTime:new Date(),
      endTime:new Date()
    };
  }


}

function oldSystemPerformAddData(){
  this.addDate = {
    yuanData:{},
    proName:'',
    sysName:'',
    busName:'',
    timeT:'',
    isAdd:false,
    data:{
      currentAvgResponseTime:[],
      historyAvgResponseTime:[],
      responseTimeMax:[],
      responseTimeMin:[]
    }

  };
}

})();